package collection;

import space.position.Point;

import java.util.*;

public class Get {
    /**
     * 静态方法的泛型需定义在static修饰符之后返回值类型之
     * */
    public static <T> ArrayList<T> getArrayList(T[] es) {
        return new ArrayList<>(Arrays.asList(es));
    }

//    public ArrayList<E> getArrayList(E[] es) {
//        ArrayList<E> arrayList = new ArrayList<>();
//        for (E e : es)
//            arrayList.add(e);
//        return arrayList;
//    }

    public static <T> LinkedList<T> getLinkedList(T[] es) {
        return new LinkedList<>(Arrays.asList(es));
    }

    public static List<String> getStringLinkedList() {
        List<String> list = new LinkedList<>();
        list.add("aa");
        list.add("ff");
        list.add("cc");
        list.add("uu");
        list.add("rr");
        list.add("vv");
        list.add("yy");
        list.add("ss");
        list.add("qq");
        list.add("oo");
        list.add("bb");
        list.add("mm");
        return list;
    }

    public static LinkedList<Point> getPointLinkedList(int eNum, int xStart, int xEnd, int yStart, int yEnd) {
        LinkedList<Point> pointList = new LinkedList<>();
        addRandomPointToCollection(pointList, eNum, xStart, xEnd, yStart, yEnd);
        return pointList;
    }
    public static LinkedList<Point> getPointLinkedList(int eNum, int xEnd, int yEnd) {
        return getPointLinkedList(eNum, 0, xEnd, 0, yEnd);
    }

    private static void addRandomPointToCollection(Collection<Point> collection, int eNum, int xStart, int xEnd, int yStart, int yEnd) {
        int xBound = xEnd - xStart;
        int yBound = yEnd - yStart;
        Random random = new Random();
        for (int i = 0; i < eNum; i++)
            collection.add(new Point(random, xBound, xStart, yBound, yStart));
    }

    public static HashSet<Point> getPointHashSet(int eNum, int xStart, int xEnd, int yStart, int yEnd) {
        HashSet<Point> points = new HashSet<>();
        addRandomPointToCollection(points, eNum, xStart, xEnd, yStart, yEnd);
        return points;
    }
    public static HashSet<Point> getPointHashSet(int eNum, int xEnd, int yEnd) {
        return getPointHashSet(eNum, 0, xEnd, 0, yEnd);
    }
}
